package com.foreknow.elmboot.controller;

import com.foreknow.elmboot.po.DeliveryAddress;
import com.foreknow.elmboot.service.DeliveryAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/DeliveryAddressController")
public class DeliveryAddressController {

    @Autowired
    private DeliveryAddressService deliveryAddressService;

    @RequestMapping("/readAddress")
    public List<DeliveryAddress> readAddress(Integer userId) throws Exception{
        return deliveryAddressService.readAddress(userId);
    }

    @RequestMapping("/getDeliveryAddressById")
    public DeliveryAddress getDeliveryAddressById(Integer daId) throws Exception {
        return deliveryAddressService.getDeliveryAddressById(daId);
    }

    @RequestMapping("/reviseDeliveryAddress")
    public int reviseDeliveryAddress(Integer daId,
                                     String contactName,
                                     Integer contactSex,
                                     String contactTel,
                                     String address,
                                     Integer userId) throws Exception {
        return deliveryAddressService.reviseDeliveryAddress(daId,contactName,contactSex,contactTel,address,userId);
    }

    @RequestMapping("/deleteDeliveryAddress")
    public int deleteDeliveryAddress(Integer daId) throws Exception {
        return deliveryAddressService.deleteDeliveryAddress(daId);
    }

    @RequestMapping("/saveDeliveryAddress")
    public int saveDeliveryAddress(String contactName,
                                   Integer contactSex,
                                   String contactTel,
                                   String address,
                                   Integer userId) throws Exception {
        return deliveryAddressService.saveDeliveryAddress(contactName,contactSex,contactTel,address,userId);
    }
}
